"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var api_1 = require("../../../../config/api");
var CategoryComponent = /** @class */ (function () {
    function CategoryComponent(httpService) {
        this.httpService = httpService;
        this.firLevel = [];
        this.secLevel = [];
        this.isShow = false;
    }
    CategoryComponent.prototype.ngOnInit = function () {
        this.getClassList(0, 'firLevel');
    };
    // 获取类型列表
    CategoryComponent.prototype.getClassList = function (parent_id, container) {
        var _this = this;
        var url = api_1.adSystemApiUrl + "/v1/admin/account/getClassByParent?parent_id=" + parent_id;
        return this.httpService.httpPostAuth(url, '').subscribe(function (res) {
            if (res.code === 2000) {
                _this[container] = res.data;
            }
            else {
                _this.type = 'error';
                _this.message = res.message;
                _this.isShow = true;
            }
        });
    };
    // 选中类目
    CategoryComponent.prototype.chosedCategory = function (level, id) {
        if (level === 0) {
            this.firId = id;
            this.secId = 0;
            this.getClassList(id, 'secLevel');
        }
        else {
            this.secId = id;
        }
    };
    // 添加类目
    CategoryComponent.prototype.addCategory = function (level) {
        if (level === 0) {
            if (!this.addFirName) {
                this.type = 'info';
                this.message = '请输入类目名称';
                this.isShow = true;
            }
            else {
                this.addCategorySubmit(this.addFirName, 0);
            }
        }
        else {
            if (!this.addSecName) {
                this.type = 'info';
                this.message = '请输入类目名称';
                this.isShow = true;
                return;
            }
            if (!this.firId) {
                this.type = 'info';
                this.message = '请先选择一级类目';
                this.isShow = true;
                return;
            }
            this.addCategorySubmit(this.addSecName, this.firId);
        }
    };
    // 添加类目
    CategoryComponent.prototype.addCategorySubmit = function (class_name, parent_id) {
        var _this = this;
        var url = api_1.adSystemApiUrl + "/v1/admin/account/add_class";
        var data = { class_name: class_name, parent_id: parent_id };
        return this.httpService.httpPostAuth(url, data).subscribe(function (res) {
            if (res.code === 2000) {
                _this.type = 'success';
                _this.message = '添加类目成功';
                _this.isShow = true;
                if (parent_id === 0) {
                    _this.addFirName = '';
                    _this.getClassList(0, 'firLevel');
                }
                else {
                    _this.addSecName = '';
                    _this.getClassList(_this.firId, 'secLevel');
                }
            }
            else {
                _this.type = 'error';
                _this.message = res.message;
                _this.isShow = true;
            }
        });
    };
    CategoryComponent = __decorate([
        core_1.Component({
            selector: 'app-category',
            templateUrl: 'category.component.html',
            styleUrls: ['category.component.scss']
        })
    ], CategoryComponent);
    return CategoryComponent;
}());
exports.CategoryComponent = CategoryComponent;
